<template>
  <div class="tree">
    <el-tree
      ref="leftTree"
      class="left-tree"
      :empty-text="$store.getters.dataText"
      :data="treeList"
      :props="defaultProps"
      default-expand-all
      :highlight-current="true"
      node-key="categoryId"
      :current-node-key="currentKey"
      :filter-node-method="filterNode"
      :expand-on-click-node="false"
      @node-click="handleNodeClick"
    >
      <div slot-scope="{ node, data }" class="custom-tree-node">
        <DtOverTooltip :content="data.categoryName" />
      </div>
    </el-tree>
  </div>
</template>

<script>
import { processCategory } from '@/framework/api/affairManage/initiateApplicationConfig/Config'

export default {
  data() {
    return {
      treeList: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      currentKey: ''
    }
  },
  computed: {
    dialogList() {
      return [{
        id: '0',
        name: '无',
        level: 0
      }, ...this.treeList]
    }
  },
  watch: {
    filterText(val) {
      this.$refs.leftTree.filter(val)
    }
  },
  created() {
    this.getList()
  },

  methods: {
    getList() {
      processCategory().then((res) => {
        this.treeList = [{
          categoryName: '全部',
          children: (res.data || []).map((item) => {
            return { ...item, children: [] }
          }),
          categoryId: ''
        }]
        this.$emit('getTypeList', this.treeList)
        this.$nextTick(() => {
          this.currentKey = this.treeList[0].categoryId
          this.$refs.leftTree.setCurrentKey(this.currentKey)
          this.handleNodeClick(this.treeList[0])
        })
      })
    },
    filterNode(value, data) {
      if (!value) return true
      return data.typeName.indexOf(value) !== -1
    },
    handleNodeClick(row) {
      this.$emit('treeClick', row.categoryId)
    }
  }
}
</script>
<style lang="scss" scoped>
.tree{
  height: calc(100vh - 60px - 60px - 40px - 2px - 32px);
  overflow: auto;
}
.left-title{
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.txt{
  color: #131314;
  font-size: 14px;
  line-height: 24px;
  padding-left: 12px;
  position: relative;
  &::before{
    content: '';
    position: absolute;
    width: 4px;
    height: 16px;
    background: var(--themeColor);
    left:0;
    top: 4px;
  }
}
.left-tree{
  margin-top: 12px;
}
  ::v-deep .el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content{
        background-color:var(--lightOpacity)
  }
::v-deep .el-tree-node__content:hover, .el-upload-list__item:hover{
  background-color:var(--lightOpacity)
}
::v-deep .el-tree-node__content{
    height: 38px;
    margin: 1px 0px;
    line-height:38px;
    overflow: hidden;
  }
.custom-tree-node{
  display: flex;
  align-items: center;
  overflow: hidden;
  width: 100%;
  .tree-name{
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex:1;
  }
  .btn{
    margin-left: 24px;
    color: var(--themeColor);

  .edit-btn{
    margin-right: 8px;

  }
  .del-btn{
    color:#F56C6C ;

  }
}
}
.active{
  margin-left: 24px;
  cursor:not-allowed;
  .edit-btn{
    margin-right: 8px;
    color: #cfd0d3;
    pointer-events:none;
  }
  .del-btn{
    pointer-events:none;
    color: #fab6b6;
  }
}
</style>

